﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kokomo.Mirror.CliMetadata.Signatures;
using System.Reflection;

namespace Kokomo.Mirror.CliMetadata
{
	class CliUnresolvedMethodInfo : CliMethodInfoBase
	{
		public CliUnresolvedMethodInfo(
			CliMemberBasicInfo basicInfo,
			MethodDefSignature signature,
			string name
			)
			: base(basicInfo, name)
		{
			if (signature == null) throw new ArgumentNullException("signature");
			this._signature = signature;
			this._name = name;
		}

		private MethodDefSignature _signature;
		private string _name;

		protected override ParameterInfo[] LoadParameters(out System.Reflection.ParameterInfo returnParameter)
		{
			//Type[] genericTypeArgs = this.DeclaringType.GetGenericArguments();
			//Type[] genericMethodArgs = this.GetGenericArguments();

			ParameterInfo[] parameters = new ParameterInfo[this._signature.parameters.Length];
			for (int i = 0; i < parameters.Length; i++)
			{
				Param param = this._signature.parameters[i];
				//Type parameterType = param.ResolveType(this.Module, genericTypeArgs,genericMethodArgs);
				parameters[i] = new CliParameterInfo(
					this.basicInfo,
					"arg" + i,
					ParameterAttributes.None,
					i + 1,
					param,
					null //parameterType
					);
			}

			returnParameter = null;
			return parameters;
		}

		public override MethodAttributes Attributes
		{
			get
			{
				MethodAttributes attributes = 0;
				if (!this._signature.flags.HasFlag(SignatureFlags.HasThis))
					attributes |= MethodAttributes.Static;
				attributes |= MethodAttributes.Public;

				return attributes;
			}
		}

		public override System.Reflection.MethodImplAttributes GetMethodImplementationFlags()
		{
			return MethodImplAttributes.Unmanaged;
		}
	}
}
